package net.llz.controller;


import net.llz.model.VideoDO;
import net.llz.service.VideoService;
import net.llz.util.JsonData;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 二当家小D
 * @since 2022-09-16
 */
@RestController
@RequestMapping("/api/video/v1")
public class VideoController {

    @Autowired
    private VideoService videoService;
    @GetMapping("find_id")
    public JsonData selectVideoByIs(@RequestParam(value = "video_id",required = true) int videoId){

        return JsonData.buildSuccess(videoService.findByid(videoId));
    }

    @GetMapping("find_all")
    public JsonData selectVideoAll(@RequestParam(value = "size",required = true) int size,
                                    @RequestParam(value = "page",required = true) int page){

        return JsonData.buildSuccess(videoService.findAll(size,page));
    }


    @PostMapping("video_save")
    public JsonData videoSave(@RequestBody VideoDO videoDO){
        videoService.saveVideo(videoDO);
        return JsonData.buildSuccess();
    }
    @PostMapping("video_update")
    public JsonData videoUpdate(@RequestBody VideoDO videoDO){
        videoService.update(videoDO);
        return JsonData.buildSuccess();
    }
    @DeleteMapping("del_video")
    public JsonData videoDel(@RequestParam(value = "video_id",required = true) int video_id){
        videoService.delete(video_id);
        return JsonData.buildSuccess(videoService.delete(video_id));
    }



}

